package com.kevin.himly.account.from.service;

import com.kevin.himly.account.from.client.AccountClient;
import com.kevin.himly.account.from.entity.Account;
import com.kevin.himly.account.from.mapper.AccountMapper;
import org.dromara.hmily.annotation.Hmily;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl {

    @Autowired
    AccountClient accountClient;
    @Autowired
    AccountMapper accountMapper;

    public void setAccountClient(AccountClient accountClient) {
        this.accountClient = accountClient;

    }

    @Hmily(confirmMethod = "confirmUpdate", cancelMethod = "cancelUpdate")
    public void update(Long id, BigDecimal transMoney, Long toId) {
        Account account = new Account();
        account.setId(id);
        account.setBalance(transMoney);
        accountMapper.update(account);
        accountClient.account(toId, transMoney);
        System.out.println("扣钱");
    }

    public void confirmUpdate(Account account) {
        System.out.println("扣钱   确认==>");
    }

    public void cancelUpdate(Long id, BigDecimal transMoney, Long toId) {
        Account account = new Account();
        account.setId(id);
        account.setBalance(transMoney);
        accountMapper.update(account);
        System.out.println("入账   取消 ==>");
    }
}
